package ${serviceImpPackage};

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.List;
import javax.annotation.Resource;
import com.alibaba.fastjson.JSON;
import ${entityPackage}.${className};
import ${commonPackage}.entity.Pagination;
import ${commonPackage}.enums.FailureCodeEnum;
import ${servicePackage}.${className}Service;
import ${commonPackage}.entity.Result;
import ${managerPackage}.${className}Manager;

 /**
 * 描述：</b>${codeName}服务接口实现<br>
 * @author：系统生成
 * @version:1.0
 */
@Service("${lowerName}Service")
public class ${className}ServiceImpl implements ${className}Service {

	private final static Logger logger= LoggerFactory.getLogger(${className}ServiceImpl.class);
	
	@Resource
	private ${className}Manager ${lowerName}Manager;
	
	/**
	 * (non-Javadoc)
	 * @see ${servicePackage}.${className}Service#insert${className}(${entityPackage}.${className})
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Result<${className}> insert${className}(${className} ${lowerName}){
		logger.info("插入${codeName}："+JSON.toJSONString(${lowerName}));
		try {
			${lowerName} = ${lowerName}Manager.insert${className}(${lowerName});
		} catch (Exception e) {
			logger.error("插入${codeName}失败",e);
			return Result.getFailureResult(FailureCodeEnum.DATA_SAVE_ERROR.getCode(), e.getMessage());
		}
		return Result.getSuccessResult(${lowerName});
	}
	
	<#if columnKeyParam !="">
     /**
	 * (non-Javadoc)
	 * @see ${servicePackage}.${className}Service#query${className}ByPrimaryKey(<#list columnKeyDatas as item><#if item_index==0>java.lang.${item.dataType}<#else>,java.lang.${item.dataType}</#if></#list>)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Result<${className}> query${className}ByPrimaryKey(${columnKeyParam}){
		logger.info("根据主键查询${codeName}："+${columnKeyParamValuePrint});
		${className} ${lowerName} = null;
		try {
			${lowerName} = ${lowerName}Manager.query${className}ByPrimaryKey(${columnKeyParamValue});
		} catch (Exception e) {
			return Result.getFailureResult(FailureCodeEnum.DATA_QUERY_ERROR.getCode(), e.getMessage());
		}
		return Result.getSuccessResult(${lowerName});
	}
	</#if>

	/**
	 * (non-Javadoc)
	 * @see ${servicePackage}.${className}Service#update${className}ByPrimaryKey(${entityPackage}.${className})
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Result<${className}> update${className}ByPrimaryKey(${className} ${lowerName}){
		logger.info("更新对应的${codeName}："+JSON.toJSONString(${lowerName}));
		try {
			${lowerName}Manager.update${className}ByPrimaryKey(${lowerName});
		} catch (Exception e) {
			logger.error("更新对应的已实名认证客户信息失败",e);
			return Result.getFailureResult(FailureCodeEnum.DATA_UPDATE_ERROR.getCode(), e.getMessage());
		}
		return Result.getSuccessResult(${lowerName});
	}
	
	/**
	 * (non-Javadoc)
	 * @see ${servicePackage}.${className}Service#update${className}ByCondition(${entityPackage}.${className})
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Result<${className}> update${className}ByCondition(${className} ${lowerName}){
		logger.info("更新对应的${codeName}："+JSON.toJSONString(${lowerName}));
		try {
			${lowerName}Manager.update${className}ByCondition(${lowerName});
		} catch (Exception e) {
			logger.error("更新对应的已实名认证客户信息失败",e);
			return Result.getFailureResult(FailureCodeEnum.DATA_UPDATE_ERROR.getCode(), e.getMessage());
		}
		return Result.getSuccessResult(${lowerName});
	}

	<#if columnKeyParam !="">
	/**
     * (non-Javadoc)
	 * @see ${servicePackage}.${className}Service#delete${className}ByPrimaryKey(<#list columnKeyDatas as item><#if item_index==0>java.lang.${item.dataType}<#else>,java.lang.${item.dataType}</#if></#list>)
     */
    @SuppressWarnings("unchecked")
    @Override
	public Result<String> delete${className}ByPrimaryKey(${columnKeyParam}){
		logger.info("删除对应的${codeName}："+${columnKeyParamValuePrint});
		try {
			${lowerName}Manager.delete${className}ByPrimaryKey(${columnKeyParamValue});
		} catch (Exception e) {
			logger.error("删除对应的${codeName}失败",e);
			return Result.getFailureResult(FailureCodeEnum.DATA_UPDATE_ERROR.getCode(), e.getMessage());
		}
		return Result.getSuccessResult();
	}
	</#if>
	
	/**
	 * (non-Javadoc)
	 * @see ${servicePackage}.${className}Service#query${className}ByPage(${entityPackage}.${className})
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Result<Pagination<${className}>> query${className}ByPage(${className} ${lowerName}){
		logger.info("根据条件查询${codeName}分页信息："+JSON.toJSONString(${lowerName}));
		Pagination<${className}> page = null;
		try {
			page = ${lowerName}Manager.query${className}ByPage(${lowerName});
		} catch (Exception e) {
			logger.error("根据条件查询${codeName}分页信息失败",e);
			return Result.getFailureResult(FailureCodeEnum.DATA_UPDATE_ERROR.getCode(), e.getMessage());
		}
		return Result.getSuccessResult(page);
	}
	
	/**
	 * (non-Javadoc)
	 * @see ${servicePackage}.${className}Service#query${className}ListByCondition(${entityPackage}.${className})
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Result<List<${className}>> query${className}ListByCondition(${className} ${lowerName}){
		logger.info("根据条件查询${codeName}列表信息："+JSON.toJSONString(${lowerName}));
		List<${className}> list = null;
		try {
			list = ${lowerName}Manager.query${className}ListByCondition(${lowerName});
		} catch (Exception e) {
			logger.error("根据条件查询${codeName}列表信息失败",e);
			return Result.getFailureResult(FailureCodeEnum.DATA_UPDATE_ERROR.getCode(), e.getMessage());
		}
		return Result.getSuccessResult(list);
	}
	
	/*user customize code start*/
${userCustomCode}
	/*user customize code end*/
}
